#ifndef __2__THREADPOOL__
#define __2__THREADPOOL__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/wait.h>
#include <syslog.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <signal.h>
#include <sys/time.h>
#include <pthread.h>
#include <stdbool.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <shadow.h>
#include <crypt.h>
#define ARGS_CHECK(argc,n)  {      \
     if(argc!=n){                  \
         fprintf(stderr,"ERROR:expected %d arguments.\n",n);\
         exit(1);                  \
     }                             \
}

#define ERROR_CHECK(ret,val,msg)  {\
    if(ret==val){                  \
       perror(msg);                \
       exit(1);                    \
    }                              \
}
#define THREAD_ERROR_CHECK(ret,msg) {if(ret != 0){fprintf(stderr,"%s:%s\n",msg,strerror(ret));}}
#define SIZE(a) (sizeof(a)/sizeof(a[0]))

#include "taskQueue.h"
typedef struct threadPool_s
{
    pthread_t *tidArr;
    int threadnum;
    taskQueue_t taskQueue;
    int exitFlag;
} threadPool_t;

int threadPoolInit(threadPool_t *threadPool, int workernum);
int makeWorker(threadPool_t *threadPool);
int tcpInit(const char *ip, const char *port, int *psockfd);
int epollAdd(int epfd, int fd);
int epollDel(int epfd, int fd);
int netDriveCd(char *pathname, const char *dirname, int netfd);
int netDriveLs(const char *pathname, int netfd);
int netDrivePuts(const char *pathname, const char *filename, int netfd);
int netDriveGets(const char *pathname, const char *filename, int netfd);
int netDrivePwd(const char *pathname, int netfd);
int netDriveRemove(const char *pathname, const char *filename, int netfd);
int netDriveMkdir(const char *pathname, const char *dirname, int netfd);
int netDriveRmdir(const char *pathname, const char *dirname, int netfd);
int userCheck(int netfd);
#define netDriveLogRequest(username)  {           \
    time_t now=time(NULL);                        \
    syslog(LOG_INFO,"username=%s,time=%s",username,ctime(now))\
}

#define netDriveLogCommand(username,command,arg)  {  \
    syslog(LOG_INFO,"username=%s,command=%s,arg=%s",username,command,arg) \
}
#endif
